package close.mazegame.entity.mob;

import close.mazegame.art.tanks.TankTexture;
import close.mazegame.collision.Collidable;
import close.mazegame.entity.Tank;
import close.mazegame.entity.mob.behaviour.TargetBehaviour;
import close.mazegame.entity.projectile.Projectile;
import close.mazegame.level.MazeLevel;
import close.mazegame.pathfinding.Pathfinder;

import com.badlogic.gdx.math.Vector2;

public abstract class AITank extends Tank {
	
	protected TargetBehaviour behaviour;
	protected Pathfinder pathfinder;

	public AITank(Vector2 pos, MazeLevel level, TankTexture texture, Pathfinder pathfinder, boolean hasTurret) {
		super(pos, level, texture, hasTurret);
		this.pathfinder = pathfinder;
	}

	public void update(float delta) {
		if(getPosition().dst(behaviour.getTarget()) < getXSize()){
			behaviour.setTarget();
		}
		if(getPosition().dst(behaviour.getTarget()) > getXSize()){
			super.move(delta, behaviour.getTargetDirection(), behaviour.getTargetTurrentAngle());
		}
	}
	
	protected short getCategoryBits(){
		return EntityCategory.MOB.getBits();
	}
	
	public Pathfinder getPathfinder(){
		return pathfinder;
	}
	
	@Override
	public void startContact(Collidable other) {
		if (other instanceof Projectile) {
			this.explode();
		}
	}

}
